package com.ews.onlineexchange.service;

import java.io.Serializable;

import javax.inject.Inject;
import javax.persistence.EntityManager;
import javax.persistence.Query;

public class CodeDicService implements Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	@Inject
	EntityManager entityManager;
	protected boolean needLog = false;
	private final static String IS_EXIST_CODENAME_AND_CODEVALUE_EQL = "  "
			+" 	SELECT COUNT(*) "
			+"	FROM CodeDic dic "
			+" 	WHERE (dic.codeName = :codeName OR dic.codeValue = :codeValue) "
			+ " AND dic.codeType = :codeType "
			+ " AND dic.delFlag = '0' ";

	public boolean isExistCodeNameAndCodeValue(String codeName,String codeValue,String codeType) {
		Query query = entityManager.createQuery(IS_EXIST_CODENAME_AND_CODEVALUE_EQL);
		query.setParameter("codeName", codeName);
		query.setParameter("codeValue", codeValue);
		query.setParameter("codeType", codeType);
		long count = (long)query.getSingleResult();
		if(count == 0) return false;
		else return true;
	}

}
